home *** CD-ROM | disk | FTP | other *** search
/ MacPeople 2003 February 1 / MACPEOPLE-2003-02-01.ISO.7z / MACPEOPLE-2003-02-01.ISO / ぶらりオンラインウェアの旅 / おしゃべり漂流記 / xGates / xGates 1.2 Source Code.sit / xGates 1.2 Source Code / init.c < prev    next >
Text File  |  2002-12-08  |  12KB  |  375 lines

  1. /*
  2.     xGates -- Stunningly entertaining action game for MacOS Classic / MacOS X
  3.     Copyright (C) 2002 Sveinbjorn Thordarson <paladeen@soth.zoneit.com>
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     init.c
  20.  
  21. */
  22.  
  23. #include "structures.h"
  24. #include "externs.h"
  25. #include "prototypes.h"
  26. #include "definitions.h"
  27.  
  28. #include "DrawSprocket.h"
  29.  
  30.  
  31. //////////////////////////////////////////////////////
  32. //Gone are the days of InitMenus(), QDRandseed etc.
  33. //////////////////////////////////////////////////////
  34. void InitToolbox (void)
  35. {
  36.     long        result;
  37.  
  38.     InitCursor();
  39.     
  40.     //now, let's find out what OS we're running
  41.     Gestalt(gestaltMenuMgrAttr, &result);
  42.     
  43.         //if OS X
  44.         if(result & gestaltMenuMgrAquaLayoutMask)
  45.         {
  46.             gOS = kMacOSX;
  47.         }
  48.         else
  49.         {
  50.             gOS = kMacOSClassic;
  51.         }
  52. }
  53.  
  54. //////////////////////////////////////////////////////
  55. //Oooh, at last, my very own InitMenus function.
  56. //////////////////////////////////////////////////////
  57. void InitMenus (void)
  58. {
  59.  
  60.     if (gOS == kMacOSClassic)
  61.     {
  62.         //Load menus from rsrc
  63.         appleMenu         = GetMenu(1000);
  64.         fileMenu         = GetMenu(1001);
  65.         editMenu        = GetMenu(1002);
  66.         optionsMenu     = GetMenu(1003);
  67.         geekOptionsMenu = GetMenu(1004);
  68.         
  69.         if (appleMenu == NULL || fileMenu == NULL || editMenu == NULL || optionsMenu == NULL || geekOptionsMenu == NULL)
  70.         {
  71.             DoAlert("¥pError loading menus.", "¥pPossible corruption of executable resource fork or out of memory.");
  72.             QuitApp();
  73.         }
  74.         
  75.         //Insert them
  76.         InsertMenu(appleMenu, 0);
  77.         InsertMenu(fileMenu, 0);
  78.         InsertMenu(editMenu, 0);
  79.         InsertMenu(optionsMenu, 0);
  80.         InsertMenu(geekOptionsMenu, 0);
  81.  
  82.         HideMenuBar();
  83.     }
  84. }
  85.  
  86. //////////////////////////////////////////////////////
  87. //Load all pic resources into offscreen pixmaps
  88. //////////////////////////////////////////////////////
  89. void InitGraphics (void)
  90. {
  91.     short i;
  92.  
  93.     billPtr = LoadPicToGWorld(1000);
  94.     billPix = GetGWorldPixMap(billPtr);
  95.     
  96.     stevePtr = LoadPicToGWorld(1001);
  97.     stevePix = GetGWorldPixMap(stevePtr);
  98.     
  99.     poofPtr = LoadPicToGWorld(1002);
  100.     poofPix = GetGWorldPixMap(poofPtr);
  101.     
  102.     for (i = 0; i < 10; i++)
  103.     {
  104.         macPtr[i] = LoadPicToGWorld(2000+i);
  105.         macPix[i] = GetGWorldPixMap(macPtr[i]);
  106.     }
  107.     
  108.     chainSawPtr = LoadPicToGWorld(200);
  109.     chainSawPix = GetGWorldPixMap(chainSawPtr);
  110.     
  111.     chainSawBigPtr = LoadPicToGWorld(190);
  112.     chainSawBigPix = GetGWorldPixMap(chainSawBigPtr);
  113.     
  114.     splashPtr = LoadPicToGWorld(100);
  115.     splashPix = GetGWorldPixMap(splashPtr);
  116.  
  117.     highScorePtr = LoadPicToGWorld(110);
  118.     highScorePix = GetGWorldPixMap(highScorePtr);
  119.     
  120.     buttonsPtr = LoadPicToGWorld(160);
  121.     buttonsPix = GetGWorldPixMap(buttonsPtr);
  122.     
  123.     deptOfJusticePtr = LoadPicToGWorld(500);
  124.     deptOfJusticePix = GetGWorldPixMap(deptOfJusticePtr);
  125.     
  126.     deptOfJusticeIconPtr = LoadPicToGWorld(501);
  127.     deptOfJusticeIconPix = GetGWorldPixMap(deptOfJusticeIconPtr);
  128.     
  129.     macIconPtr = LoadPicToGWorld(300);
  130.     macIconPix = GetGWorldPixMap(macIconPtr);
  131.     
  132.     billIconPtr = LoadPicToGWorld(301);
  133.     billIconPix = GetGWorldPixMap(billIconPtr);
  134.      
  135.     sothPtr = LoadPicToGWorld(4000);
  136.     sothPix = GetGWorldPixMap(sothPtr);
  137.     
  138.     mousePtr = LoadPicToGWorld(401);
  139.     mousePix = GetGWorldPixMap(mousePtr);
  140.     
  141.     keyboardPtr = LoadPicToGWorld(400);
  142.     keyboardPix = GetGWorldPixMap(keyboardPtr);
  143.     
  144.     gamePausedPtr = LoadPicToGWorld(180);
  145.     gamePausedPix = GetGWorldPixMap(gamePausedPtr);
  146.     
  147.     cornerPtr[0] = LoadPicToGWorld(5000);
  148.     cornerPix[0] = GetGWorldPixMap(cornerPtr[0]);
  149.     
  150.     cornerPtr[1] = LoadPicToGWorld(5001);
  151.     cornerPix[1] = GetGWorldPixMap(cornerPtr[1]);
  152.     
  153.     scoreNameRectPtr = LoadPicToGWorld(195);
  154.     scoreNameRectPix = GetGWorldPixMap(scoreNameRectPtr);
  155.     
  156.     haukurSplashPtr = LoadPicToGWorld(120);
  157.     haukurSplashPix = GetGWorldPixMap(haukurSplashPtr);
  158.     
  159.     haukurHeadPtr = LoadPicToGWorld(130);
  160.     haukurHeadPix = GetGWorldPixMap(haukurHeadPtr);
  161.     
  162.     haukurWinPtr = LoadPicToGWorld(140);
  163.     haukurWinPix = GetGWorldPixMap(haukurWinPtr);
  164.  
  165. }    
  166.     
  167.  
  168. //////////////////////////////////////////////////////
  169. //Init sound channels and load SND resources
  170. //////////////////////////////////////////////////////
  171. void InitSound (void)
  172. {
  173.     short i;
  174.  
  175.     SndNewChannel(&weaponSndChannel, sampledSynth, initMono + initNoDrop, nil);
  176.     SndNewChannel(&billSndChannel, sampledSynth, initMono + initNoDrop, nil);
  177.     SndNewChannel(&steveSndChannel, sampledSynth, initMono + initNoDrop, nil);
  178.     SndNewChannel(&computerSndChannel, sampledSynth, initMono + initNoDrop, nil);
  179.     SndNewChannel(&dojSndChannel, sampledSynth, initMono + initNoDrop, nil);
  180.     SndNewChannel(&otherSndChannel, sampledSynth, initMono + initNoDrop, nil);
  181.     SndNewChannel(&musicSndChannel, sampledSynth, initMono + initNoDrop, nil);
  182.  
  183.     //weapon sounds
  184.     chainsawSnd = GetResource('snd ', 1000);
  185.         if (chainsawSnd == NULL)
  186.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  187.     jammedSnd = GetResource('snd ', 1001);
  188.         if (jammedSnd == NULL)
  189.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  190.     
  191.     //bill sounds
  192.     billScreamSnd = GetResource('snd ', 2000);
  193.         if (billScreamSnd == NULL)
  194.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  195.     billIndignantSnd = GetResource('snd ', 2001);
  196.         if (billIndignantSnd == NULL)
  197.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  198.     
  199.     //steve sounds
  200.     steveScreamSnd = GetResource('snd ', 3001);
  201.         if (steveScreamSnd == NULL)
  202.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  203.     
  204.     //computer sounds
  205.     macOSLoadedSnd = GetResource('snd ', 4000);
  206.         if (macOSLoadedSnd == NULL)
  207.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  208.     winXPLoadedSnd = GetResource('snd ', 4001);
  209.         if (winXPLoadedSnd == NULL)
  210.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  211.     
  212.     //dept of justice sounds
  213.     dojAppearsSnd = GetResource('snd ', 5001);
  214.         if (dojAppearsSnd == NULL)
  215.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  216.     dojCaughtSnd = GetResource('snd ', 5000);
  217.         if (dojCaughtSnd == NULL)
  218.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  219.     
  220.     //other sounds
  221.     bonkSnd = GetResource('snd ', 6000);
  222.         if (bonkSnd == NULL)
  223.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  224.     zoomSnd = GetResource('snd ', 6001);
  225.         if (zoomSnd == NULL)
  226.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  227.     poofSnd = GetResource('snd ', 6002);
  228.         if (poofSnd == NULL)
  229.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  230.     gongSnd = GetResource('snd ', 6003 );
  231.         if (gongSnd == NULL)
  232.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  233.     beepSnd = GetResource('snd ', 6004 );
  234.         if (beepSnd == NULL)
  235.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  236.     
  237.     //game sounds
  238.     gameOverSnd = GetResource('snd ', 7000);
  239.         if (gameOverSnd == NULL)
  240.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  241.     gamePausedSnd = GetResource('snd ', 7001);
  242.         if (gamePausedSnd == NULL)
  243.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  244.     yeahSnd = GetResource('snd ', 7002);
  245.         if (yeahSnd == NULL)
  246.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  247.     killSomeBillSnd = GetResource('snd ', 7003);
  248.         if (killSomeBillSnd == NULL)
  249.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  250.     goodJobSound = GetResource('snd ', 7004);
  251.         if (goodJobSound == NULL)
  252.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  253.     
  254.     //music sounds
  255.     musicSounds[0] = GetResource('snd ', 10000);
  256.     musicSounds[1] = GetResource('snd ', 10001);
  257.     musicSounds[2] = GetResource('snd ', 10002);
  258.     musicSounds[3] = GetResource('snd ', 10003);
  259.     musicSounds[4] = GetResource('snd ', 10004);
  260.     musicSounds[5] = GetResource('snd ', 10005);
  261.     
  262.     for (i = 0; i < 6; i++)
  263.     {
  264.         if (musicSounds[i] == NULL)
  265.             FatalErrorAlert("¥pError loading sounds", "¥pFunction: InitSound();");
  266.     }
  267.     
  268. }
  269.  
  270. #pragma mark -
  271.  
  272.  
  273. //////////////////////////////////////////////////////
  274. //Init DrawSprockets and attempt to switch to 640x480
  275. //////////////////////////////////////////////////////
  276.  
  277. void DisplayInit (void)
  278. {
  279.  
  280.     // Startup DrawSprockets and fade to black
  281.       OSErr theError=DSpStartup();
  282.       
  283.       GDHandle graphicsDevice = DMGetFirstScreenDevice(true); // activate the Display Manager
  284.       
  285.       if (theError)
  286.     {
  287.         FatalErrorAlert("¥pError loading DrawSprockets.", "¥pDSpStartup();");
  288.     }
  289.  
  290.     if (graphicsDevice == NULL)
  291.     {
  292.         DoAlert("¥pError getting reading graphics device..", "¥pFunction: DisplayInit();  Continuing...let's see if we can get away with this anyway.");
  293.     }
  294.  
  295.       gDisplayAttributes.frequency=0;
  296.  
  297.       gDisplayAttributes.reserved1=0;
  298.  
  299.       gDisplayAttributes.reserved2=0;
  300.  
  301.       gDisplayAttributes.colorNeeds=kDSpColorNeeds_Require;
  302.  
  303.       gDisplayAttributes.colorTable=nil;
  304.  
  305.       gDisplayAttributes.contextOptions=0;
  306.  
  307.       gDisplayAttributes.gameMustConfirmSwitch=false;
  308.  
  309.       gDisplayAttributes.reserved3[0]=0;
  310.  
  311.       gDisplayAttributes.reserved3[1]=0;
  312.  
  313.       gDisplayAttributes.reserved3[2]=0;
  314.  
  315.       gDisplayAttributes.reserved3[3]=0;
  316.  
  317.       gDisplayAttributes.displayBestDepth=16;//16 bit colour
  318.  
  319.       gDisplayAttributes.displayDepthMask=kDSpDepthMask_16;
  320.  
  321.       gDisplayAttributes.backBufferBestDepth=gDisplayAttributes.displayBestDepth;
  322.  
  323.       gDisplayAttributes.backBufferDepthMask=gDisplayAttributes.displayDepthMask;
  324.  
  325.       gDisplayAttributes.pageCount = 2;//two buffers, one onscreen, one offscreen
  326.  
  327.       gDisplayAttributes.displayWidth=640;
  328.       
  329.       gDisplayAttributes.displayHeight=480; 
  330.       
  331.       
  332.       theError=DSpFindBestContext(&gDisplayAttributes, &gDisplayContext);
  333.  
  334.       if (theError)
  335.       {
  336.         FatalErrorAlert("¥pError initing DrawSprockets", "¥pA suitable display context could not be found.");
  337.       }
  338.       
  339.       //Set the blanking color to black
  340.     DSpSetBlankingColor(&myBlackColor);
  341.  
  342.       theError=DSpContext_Reserve(gDisplayContext, &gDisplayAttributes);
  343.       
  344.       if (theError) 
  345.       {
  346.           DSpContext_FadeGammaIn(NULL, NULL);
  347.         FatalErrorAlert("¥pError reserving display context.", "¥pDrawSprockets must be fucked.");
  348.       }
  349.       
  350.       DSpContext_FadeGammaOut(NULL, NULL);
  351.  
  352.     //try to change to our resolution
  353.       theError = DSpContext_SetState(gDisplayContext, kDSpContextState_Active);
  354.  
  355.       if (theError) 
  356.       {
  357.           DSpContext_FadeGammaIn(NULL, NULL);
  358.         FatalErrorAlert("¥pError setting display resolution with DrawSprockets.", "¥pMaybe your monitor does not support a resolution of 640 by 480 pixels. ;");
  359.       }
  360.  
  361.       theError = DSpContext_FadeGammaIn(NULL, NULL);
  362. }
  363.  
  364.  
  365.  
  366. void DisplayReset(void)
  367. {
  368.     DSpContext_FadeGammaOut(nil, nil);
  369.     
  370.     DSpContext_SetState(gDisplayContext, kDSpContextState_Inactive);
  371.     DSpContext_FadeGammaIn(nil, nil);
  372.  
  373.     DSpContext_Release(gDisplayContext);
  374.     DSpShutdown();
  375. }